home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / BARNET / FREENET / FERGUSON / CLIENT_P / !Client_Ex / c / Command < prev    next >
Text File  |  1995-06-05  |  5KB  |  179 lines

  1. /*
  2.  
  3. File:               Command.c
  4. Date:               03-Jun-1995
  5. Author:             © Duncan Ferguson
  6. File Purpose:       provide window to get server Command with
  7. Version:            0.01
  8.  
  9. */
  10.  
  11. /* handle the command window and its button clicks */
  12.  
  13. /* ============================================================= */
  14. /* |                Include files                   | */
  15. /* ============================================================= */
  16. #include "Command.h"
  17.  
  18. #include "Connect.h"
  19. #include "Client_Ex.h"
  20.  
  21. #include "NetLib:netdb.h"
  22.  
  23. #include "DeskLib:Error.h"
  24. #include "DeskLib:Event.h"
  25. #include "DeskLib:Handler.h"
  26. #include "DeskLib:Icon.h"
  27. #include "DeskLib:Msgs.h"
  28. #include "DeskLib:Window.h"
  29. #include "DeskLib:WIMP.h"
  30.  
  31. #include <string.h>
  32. #include <assert.h>
  33. #include <stdio.h>
  34.  
  35. /* ============================================================= */
  36. /* |                    #Definitions                           | */
  37. /* ============================================================= */
  38. #define BUFFER_SIZE 1024
  39.  
  40. /* ============================================================= */
  41. /* |                     Structures                            | */
  42. /* ============================================================= */
  43.  
  44. /* icon numbers */
  45. static enum {
  46.   command_HELP,   /* = 0 */
  47.   command_LIST,
  48.   command_POST,
  49.   command_NEWNEWS,
  50.   command_NEWNEWS_TEXT,  /* = 4 */
  51.   command_ARTICLE,
  52.   command_ARTICLE_TEXT,
  53.   command_GROUP,
  54.   command_GROUP_TEXT,
  55.   command_IHAVE,
  56.   command_SLAVE,
  57.   command_QUIT      /* = 11 */
  58. };
  59.  
  60. /* ============================================================= */
  61. /* |              Global variables                   | */
  62. /* ============================================================= */
  63. static window_handle Command_Window = 0;
  64.  
  65. /* ============================================================= */
  66. /* |                  Function Prototypes                      | */
  67. /* ============================================================= */
  68. static BOOL Command_ClickHandler(event_pollblock *event, void *reference);
  69. static BOOL Command_Delete(event_pollblock *event, void *reference);
  70.  
  71. /* ============================================================= */
  72. /* |                  External functions                       | */
  73. /* ============================================================= */
  74. extern void Command_Open(void)
  75. {
  76.   if(!Command_Window)
  77.   {
  78.     Command_Window = Window_CreateAndShow("Commands", 0, open_WHEREVER);
  79.  
  80. /* error occured in getting template */
  81.     if(Command_Window == 0)
  82.     {
  83.       Msgs_Report(0, "no.template");
  84.       return;
  85.     }
  86.  
  87.     Event_Claim(event_CLOSE, Command_Window, event_ANY, Command_Delete,
  88.       &Command_Window);
  89.     Event_Claim(event_OPEN, Command_Window, event_ANY, Handler_OpenWindow,
  90.       NULL);
  91.     Event_Claim(event_CLICK, Command_Window, event_ANY, Command_ClickHandler,
  92.       NULL);
  93.  
  94.     Icon_SetText(Command_Window, command_NEWNEWS_TEXT, NULL);
  95.     Icon_SetText(Command_Window, command_ARTICLE_TEXT, NULL);
  96.     Icon_SetText(Command_Window, command_GROUP_TEXT,   NULL);
  97.   }
  98.   else
  99.   {
  100.     Window_BringToFront(Command_Window);
  101.   }
  102. }
  103.  
  104. /* ============================================================= */
  105. /* |                  Internal functions                       | */
  106. /* ============================================================= */
  107.  
  108. static BOOL Command_ClickHandler(event_pollblock *event, void *reference)
  109. {
  110.   char Buffer[BUFFER_SIZE+1];
  111.   char Command[BUFFER_SIZE+1];
  112.  
  113.   /* kill compiler warning */
  114.   UNUSED(reference);
  115.  
  116.   switch(event->data.mouse.icon)
  117.   {
  118.     case command_HELP:
  119.       sprintf(Command, "HELP\r\n\0");
  120.       break;
  121.  
  122.     case command_LIST:
  123.       sprintf(Command, "LIST\r\n\0");
  124.       break;
  125.  
  126.     case command_POST:
  127.       sprintf(Command, "POST\r\n\0");
  128.       break;
  129.  
  130.     case command_NEWNEWS:
  131.       Icon_GetText(Command_Window, command_NEWNEWS_TEXT, Buffer);
  132.       sprintf(Command, "NEWNEWS %s\r\n\0", Buffer);
  133.       break;
  134.  
  135.     case command_ARTICLE:
  136.       Icon_GetText(Command_Window, command_ARTICLE_TEXT, Buffer);
  137.       sprintf(Command, "ARTICLE %s\r\n\0", Buffer);
  138.       break;
  139.  
  140.     case command_GROUP:
  141.       Icon_GetText(Command_Window, command_GROUP_TEXT, Buffer);
  142.       sprintf(Command, "GROUP %s\r\n\0", Buffer);
  143.       break;
  144.  
  145.     case command_IHAVE:
  146.       sprintf(Command, "IHAVE\r\n\0");
  147.       break;
  148.  
  149.     case command_SLAVE:
  150.       sprintf(Command, "SLAVE\r\n\0");
  151.       break;
  152.  
  153.     case command_QUIT:
  154.       sprintf(Command, "QUIT\r\n\0");
  155.       break;
  156.   }
  157.  
  158.   if(!Connect_SendMessage(Command))
  159.   {
  160.     Error_Report(0, "The message could not be sent for some reason");
  161.   }
  162.  
  163.   return TRUE;
  164. }
  165.  
  166. static BOOL Command_Delete(event_pollblock *event, void *reference)
  167. {
  168.    window_handle *window = reference;
  169.  
  170.    assert(event->data.openblock.window == *window);
  171.    /* make sure window handles match */
  172.  
  173.    Window_Delete(event->data.openblock.window);
  174.  
  175.    *window = 0;
  176.  
  177.    return TRUE;
  178. }
  179.